home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 105 (1991-02)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 105 (1991-02)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / AmigaUUCP / uucico / modem.c < prev    next >
C/C++ Source or Header  |  1991-02-08  |  4KB  |  231 lines

  1.  
  2. /*
  3.  *  MODEM.C
  4.  *
  5.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  6.  *
  7.  *  $Header: Beta:src/uucp/src/uucico/RCS/modem.c,v 1.1 90/02/02 11:56:00 dillon Exp Locker: dillon $
  8.  */
  9.  
  10. #include "includes.h"
  11. #include "uucp.h"
  12. #include "log.h"
  13.  
  14. Prototype void openline(void);
  15. Prototype int  get_baud(void);
  16. Prototype void modem_init(void);
  17. Prototype int  dial_nbr(const char *);
  18. Prototype void reset_modem(void);
  19.  
  20. /*
  21.  *  NOTE:   modem stuff pretty much ignored if we are run from
  22.  *        a getty.
  23.  */
  24.  
  25. #define MULTIMODEM    /*  I have a multi-modem    */
  26.  
  27. extern int Getty;
  28. extern int IgnoreCD;
  29.  
  30.  
  31.  
  32. void
  33. openline()
  34. {
  35.     int to = 0;
  36.  
  37.     {
  38.     char *ptr;
  39.     if (ptr = FindConfig(CTIMEOUT))
  40.         to = atoi(ptr);
  41.     }
  42.  
  43.  
  44.     signal(SIGINT,sigint);
  45.     IgnoreCD |= 4;
  46. start_again:
  47.     chkabort();
  48.     if (instr("CONNECT", 7, to))
  49.     goto start_again;
  50.  
  51.  
  52. #ifdef MULTIMODEM
  53.  
  54. #else
  55.     set_baud(get_baud());
  56. #endif
  57.     Delay(120); /* sleep 2 seconds */
  58.  
  59.     IgnoreCD &= ~4;
  60. }
  61.  
  62. #ifndef MULTIMODEM
  63.  
  64. int
  65. get_baud()
  66. {
  67. /* We've seen the CONNECT message, now we must see what baud rate
  68.    we've connected with */
  69. /* gather input until \r then see if it's 300, 1200, or 2400 */
  70. /* this is for hayes compatibles */
  71.  
  72.     int data;
  73.     char rate[10];
  74.     int rate_inx = 0;
  75.  
  76.     DEBUG(2,"looking for baud rate\n",0);
  77.  
  78.     while ( ((data = xgetc(BYTE_TO)) != EOF) && ((char)data != '\r')) {
  79.         if ((char)data == ' ') continue;
  80.         rate[rate_inx++] = (char)data;
  81.     }
  82.     DEBUG(2, "found baud rate of %s\n", rate);
  83.     if (strncmp(rate,"1200",4) == 0) return 1200;
  84.     if (strncmp(rate,"2400",4) == 0) return 2400;
  85.     if (rate_inx == 0) return 300;
  86.     return 1200;  /* default */
  87. }
  88.  
  89. #endif
  90.  
  91. void
  92. modem_init()
  93. {
  94.     reset_modem();
  95. }
  96.  
  97. /*
  98.  * Simple dialer routine.  Needs replacement with a full blown
  99.  * script driven dialer.  Next week maybe :-).    FIXME.
  100.  */
  101.  
  102. int
  103. dial_nbr(nbr)
  104. const char *nbr;
  105. {
  106.     char  *dial;
  107.     int   i;
  108.     int   to = 0;
  109.  
  110.     if (dial = FindConfig(CTIMEOUT))
  111.     to = atoi(dial);
  112.  
  113.     IgnoreCD |= 4;
  114.  
  115.     twrite("\rAT\r", 4);
  116.     Delay(50);
  117.  
  118.     if (dial = FindConfig(MODEMINIT))
  119.     xlat_str(dial);
  120.     dial = malloc(strlen(nbr) + 16);
  121.     dial[0] = 0;
  122.     if (strnicmp(nbr, "AT", 2) != 0)
  123.     strcpy(dial, "ATDT");
  124.     strcat(dial, nbr);
  125.     strcat(dial, "\r");
  126.  
  127.     DEBUG(2,"dialing %s\n", dial);
  128.     twrite(dial, strlen(dial));
  129.  
  130.     i = instr("CONNECT", 7, to);
  131.  
  132.     if (i == 0)     /*  for those modems which don't bring CD up */
  133.     Delay(50);  /*  immediately                              */
  134.  
  135.     IgnoreCD &= ~4;
  136.  
  137.     free(dial);
  138.  
  139.     return (i);
  140. }
  141.  
  142. /*
  143.  *  RESET_MODEM()
  144.  *
  145.  *  If run from a Getty we do NOT reset the modem, which would
  146.  *  disconnect an already connected connection.
  147.  *
  148.  *  Note that the delay between CloseSerial() and OpenSerial() only
  149.  *  serves to give the Getty, if running, time to lock the port and
  150.  *  begin a disconnect sequence.
  151.  */
  152.  
  153. void
  154. reset_modem()
  155. {
  156.     if (Getty)          /*  called from a getty             */
  157.     return;
  158.     DEBUG(4, "Beg-Reset\n", 0);
  159.     if (CheckCarrier()) {
  160.     if (IgnoreDTR) {
  161.         xwrite("\r", 1);        /*  hangup the dial?    */
  162.         Delay(50*2);
  163.         xwrite("+++", 3);
  164.         Delay(50*4);
  165.         xwrite("\r", 1);
  166.         Delay(50);
  167.         xwrite("ATH0\r", 5);
  168.         Delay(50);
  169.     } else {
  170.         CloseSerial(0);     /*  drop dtr            */
  171.         Delay(50*3);        /*  delay 3 seconds     */
  172.         DEBUG(4, "End-Reset-1\n", 0);
  173.         OpenSerial(0);      /*  re-open serial      */
  174.     }
  175.     } else {
  176.     xwrite("\r", 1);        /*  hangup the dial?    */
  177.     }
  178.     DEBUG(4, "End-Reset-2\n", 0);
  179. }
  180.  
  181. #ifdef NOTDEF
  182.  
  183.     if (GettyCmd(DeviceName, DeviceUnit, '0', NULL) == 0)
  184.     return;
  185.  
  186.     /*
  187.      *    Getty doesn't exist, we have to reset the modem ourselves!
  188.      */
  189.  
  190.     IgnoreCD |= 4;
  191.  
  192. #ifdef MULTIMODEM
  193.     set_baud(19200);
  194.  
  195.     if (CheckCarrier()) {
  196.     Delay(60);
  197.     twrite("+++", 3);
  198.     Delay(120);
  199.     }
  200.     twrite("ATH0\r", 5);
  201.     instr("OK\r\n", 4, 3);
  202.     twrite("ATZ\r", 4);
  203.     instr("OK\r\n", 4, 3);
  204.     twrite("ATZ\r", 4);
  205.     instr("OK\r\n", 4, 3);
  206.  
  207.     /*amiga_closeopen();*/
  208.     sprintf(init, "%s\r", "ATM0S0=2X4$BA0");
  209.     if (debug > 0)
  210.     init[3] = '1';
  211.     twrite(init, strlen(init));
  212.     instr("OK\r\n", 4, 3);
  213. #else
  214.     twrite("+++", 3);
  215.     Delay(60);
  216.     twrite("ATH0\r", 5);
  217.     Delay(120);
  218.     twrite("ATZ\r", 4);
  219.     Delay(60);
  220.     twrite("ATZ\r", 4);
  221.     Delay(60);
  222.     sprintf(init, "%s\r", "ATS2");
  223.     twrite(init, strlen(init));
  224.     Delay(60);
  225. #endif
  226.     IgnoreCD &= ~4;
  227. }
  228.  
  229. #endif
  230.  
  231.